package com.lz.football.module.activity.timelimitDiscount
{
	import com.common.utils.Reflection;
	import com.global.GlobalDef;
	import com.liangzhong.constants.ResourceConst;
	import com.liangzhong.events.ActivityEvent;
	import com.liangzhong.events.ModuleEvent;
	import com.liangzhong.manager.ResourceManager;
	import com.liangzhong.model.AppData;
	import com.liangzhong.model.activity.ActivityTimeLimitVo;
	import com.liangzhong.model.goods.vo.GoodsVo;
	import com.lz.football.module.activity.IActivity;
	
	import common.BaseView.BaseView;
	
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import flash.text.TextField;

	/**
	 *限时打折  
	 * @author Administrator
	 * 
	 */	
	public class TimelimitDiscountView extends BaseView implements IActivity
	{
		/**
		 *容器
		 *  
		 */
		private var contain:MovieClip;
		/**
		 * 
		 */
		private var _buyView:TimelimitBuyView;
		public function TimelimitDiscountView()
		{
			super();
		}
		
		public function baseinformation($obj:Object):void
		{
			var arr:Array = AppData.getInstance().activityDatemanager.timeLimitArr;
			if(arr == null)return;
			var len:int = arr.length;
			var item:TimelimiteBuyItem;
			for(var i:int = 0;i < len;i++)
			{
				item = new TimelimiteBuyItem();
				item.initUI();
				item.setDate(arr[i]);
				item.callBack = selectBuyItem;
				item.x = (item.width + 30) * (i % 4);
				item.y = (item.height + 10) * int(i /4);
				contain.addChild(item);
			}
			
		}
		
		public function award($obj:Object):void
		{
		}
		override public function initUI(view:Object=null):void
		{
			symbolSkin = Reflection.createInstance("com.lz.res.activity.timelimitView");
			this.addChild(symbolSkin);
			_windowBg = symbolSkin.timeLimitBg;
			_viewHeight = _windowBg.height;
			_viewWidth = _windowBg.width;
			contain = symbolSkin.contain;
			
			var time:TextField = symbolSkin.time;
//			time.text = "活动期间:至2014年2月26日截止"/;
			var xml:XML = ResourceManager.instance.getResource(ResourceConst.ACTIVITYTIME_XML);
			//			trace(xml.activity1);
			
//			var time:TextField = symbolSkin.time;
			time.text = "活动时间：" +xml.timeLimit + "截止";;
			isCloseBtn = true;
			isDrag = true;
			moveClose(_viewWidth - 30,38);
			onResizeHandler();
			addEvtListener();
//			initItem();
		}
		/**
		 *初始化item
		 *  
		 * 
		 */
		private function initItem():void
		{
			var item:TimelimiteBuyItem;
			for(var i:int = 0;i < 6;i++)
			{
				item = new TimelimiteBuyItem();
				item.initUI();
				item.callBack = selectBuyItem;
				item.x = (item.width + 30) * (i % 4);
				item.y = (item.height + 10) * int(i /4);
				contain.addChild(item);
			}
		}
		
		
		/**
		 *选择购买的item 
		 * 
		 */
		private function selectBuyItem($vo:ActivityTimeLimitVo):void
		{
			if(_buyView == null)
			{
				_buyView = new TimelimitBuyView();
				_buyView.initUI();
			}
			_buyView.setData($vo);
			GlobalDef.GameWindowContainer.addChild(_buyView);
		}
		override public function addEvtListener():void
		{
			
		}
		
		override public function removeEvtListener():void
		{
			
		}
		
		override public function destroyView():void
		{
			var item:TimelimiteBuyItem;
			while(contain.numChildren)
			{
				item = contain.removeChildAt(0) as TimelimiteBuyItem;
				item.destroyView();
				item = null;
			}
				
			super.destroyView();
			if(_buyView != null)
			{
				if(_buyView.parent)
					_buyView.parent.removeChild(_buyView);
				_buyView.destroyView();
			}
		}
		override public function onCloseHandler(event:MouseEvent):void
		{
			this.dispatchEvent(new ActivityEvent(ModuleEvent.REMOVE_MODULE));
		}
	}
}